﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;

namespace Bordspil.Models
{
    public class UserProfileRepository : IUserProfileRepository
    {
        private AppDataContext m_db = new AppDataContext();

        //Update-ar nyju profile myndina í DB
        public void UpdateUserProfile(UserProfile user)
        {
            var currUser = m_db.UserProfile.SingleOrDefault(n => n.UserName == user.UserName);
            if (currUser == null) {
                throw new Exception("Hvad i fjanda tu gera?!");
            }
            currUser.Age = user.Age;
            currUser.Email = user.Email;
            currUser.UserName = user.UserName;
            currUser.UserPicture = user.UserPicture;
            m_db.SaveChanges();
        }
        //Sækir notenda
        public UserProfile GetUserProfile(string username)
        {
            var currUser = m_db.UserProfile.SingleOrDefault(n => n.UserName == username);
            if (currUser == null)
            {
                throw new Exception("Hvad i fjanda tu gera?!");
            }
            return currUser;
        }
    }
}